﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.gates {
    import flash.events.*;
    import Engine.Managers.*;
    import Classes.*;
    import Display.*;
    import Display.GateUI.*;

    public class UpgradeInventoryGate extends InventoryGate {

        public static const GATE_NAME:String = "pre_upgrade";

        public function UpgradeInventoryGate(_arg1:String){
            super(_arg1);
        }
        override public function displayGate(_arg1:String=null, _arg2:String=null):void{
            var _local5:String;
            var _local6:Item;
            var _local7:Item;
            var _local8:String;
            var _local9:Object;
            var _local10:Item;
            m_customViralType = _arg1;
            m_dialog = null;
            var _local3:Array = new Array();
            var _local4:Player = Global.player.getFakeFriend();
            for (_local5 in m_keys) {
                _local9 = new Object();
                _local10 = Global.gameSettings.getItemByName(_local5);
                _local9.item = _local10;
                _local9.amountNeeded = m_keys[_local5];
                _local9.buyCallback = buyKey;
                _local9.askCallback = askForKey;
                _local3.push(_local9);
            };
            _local9 = new Object();
            _local9.item = Global.gameSettings.getItemByName(SEND_GIFT_ITEM);
            _local9.amountNeeded = 0;
            _local3.push(_local9);
            m_cellFactory = new KeyCellItemFactory(_local3);
            _local6 = Global.gameSettings.getItemByName(m_unlockItemName);
            _local7 = Global.gameSettings.getItemByName(m_unlockItemName);
            _local8 = _local7.type;
            if (m_dialog == null){
                if (_local8.toLowerCase() == "municipal"){
                    m_dialog = UI.displayMunInventoryUpgradesDialog(m_unlockItemName, _local3, checkForKeys, this.gateFinishHandler, this.buyAllInventory, m_targetObjectId);
                };
            };
            StatsManager.milestone(("see_gate_for_" + m_unlockItemName));
        }
        protected function buyAllInventory(_arg1:Array):Boolean{
            var _local3:String;
            var _local4:Item;
            var _local5:uint;
            var _local6:uint;
            var _local7:int;
            var _local8:uint;
            var _local2:uint;
            for (_local3 in m_keys) {
                _local4 = Global.gameSettings.getItemByName(_local3);
                _local5 = Global.player.inventory.getItemCount(_local4);
                _local6 = m_keys[_local3];
                _local7 = Math.max(0, (_local6 - _local5));
                _local8 = (_local7 * _local4.cash);
                _local2 = (_local2 + _local8);
            };
            if (Global.player.canBuyCash(_local2)){
                buyAll();
                return (true);
            };
            return (false);
        }
        protected function gateFinishHandler(_arg1:Event=null):void{
            if (checkForKeys()){
                unlockGate();
                m_dialog.close();
            } else {
                m_dialog.close();
            };
        }

    }
}//package Classes.gates 
